package servlet;

import entity.Card;
import service.CardService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/CardAdd")
public class CardAdd extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("test/html;charset=utf-8");

        Card card = new Card();
        card.setUserName(req.getParameter("username"));
        card.setIdNumber(req.getParameter("idNumber"));
        card.setStatus(1);
        card.setCreateDate(req.getParameter("createDate"));

        req.getSession().setAttribute("msg", new CardService().cardAdd(card) > 0);
        resp.sendRedirect("CardList");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
